<template>
  <div class="main-content">
    <div class="left-panel">
      <div class="card stats-card">
        <NumberStatistics />
      </div>
      <div class="card chart-card">
        <RegionalTrend :provinces="curProvinces" />
      </div>
      <div class="card chart-card">
        <ProvinceAnalysisRadar :provinces="curProvinces" />
      </div>
    </div>

    <div class="center-panel">
      <div class="map-container card">
        <BMap v-model:schools="schools" />
      </div>

      <div class="center-bottom">
        <div class="card">
          <RankingTable v-model:provinces="curProvinces" v-model:schools="schools" @update:schools="updateSchools" />
        </div>
      </div>
    </div>

    <div class="right-panel">
      <div class="card">
        <AIAssistant v-model:provinces="curProvinces" v-model:schools="schools" />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, watch } from "vue"
import { NumberStatistics, ProvinceAnalysisRadar, RegionalTrend, AIAssistant, BMap, RankingTable } from "@/components"

const curProvinces = ref<string[]>([])
const schools = ref<string[]>([])

// 更新选中的学校
const updateSchools = (newSchools: string[]) => {
  schools.value = newSchools
}

defineOptions({
  name: "HomeView"
})
</script>
<style lang="scss" scoped>
.main-content {
  flex: 1;
  display: flex;
  gap: 20px;
  height: 100%;
  min-height: 0;
  max-width: 100%;
}

.card {
  background: #fff;
  border-radius: 8px;
  padding: 10px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.left-panel,
.right-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  height: 100%;
  max-height: 100%;
  flex: 1 1 25%;
  max-width: 25%;

  .chart-card {
    //height: 300px;
    flex: 1;
  }

  .stats-card {
    height: 80px;
  }
}

.center-panel {
  max-height: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1 1 50%;
  max-width: 50%;

  .map-container {
    flex: 1 1 65%;

    .map-tools {
      margin-bottom: 20px;
    }
  }

  .center-bottom {
    display: flex;
    flex: 1 1 40%;
    gap: 20px;
    width: 100%;
    min-height: 0;

    .card {
      flex: 1 1 50%;
      overflow: hidden;
    }
  }
}

.right-panel {
  .card {
    flex: 1;
    height: calc(100% - 40px);
  }
}

.ranking-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2px;
}

.ranking-actions {
  display: flex;
  gap: 2px;
}
</style>
